<template>
  <div>
    <div class="act-comment">
      <header>
        <img src="/src/assets/icons/msg-box.png" alt="评论">
        <span>评论 ({{commentCount}})</span>
      </header>
      <footer>
        <mt-field placeholder="请输入评论" v-model="comment"></mt-field>
        <mt-button @click="releaseComment">评论</mt-button>
      </footer>
      <div class="comment" v-for="v in commentList" :key="v.id">
        <div class="head-img">
          <img :src="v.headimgurl">
        </div>
        <div class="comment-detail">
          <div class="user-name">
            <span>{{v.name}}</span>
            <span class="floor">{{v.floor}}楼</span>
            <span class="date-time">{{v.add_time}}</span>
          </div>
          <div class="detail">{{v.content}}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import {Toast} from 'mint-ui'

  export default {
    name: 'ActivityComment',
    data () {
      return {
        comment: '',
        commentList: [],
        commentCount: 0
      }
    },
    methods: {
      releaseComment () {
        const params = {
          act_id: this.$route.params.id,
          content: this.comment
        }
        if (this.comment === '') {
          msg('评论不能为空')
          return false
        }
        this.$post('/vue/activity/add_comment', params).then(data => {
          msg('评论成功')
          this.comment = ''
          this.getCommentList()
        })
      },
      getCommentList () {
        const params = {
          act_id: this.$route.params.id,
          page: 1,
          limit: 200
        }
        this.$post('/vue/activity/comment_list', params).then(data => {
          this.commentList = data.act_list
          this.commentCount = data.count
        })
      }
    },
    mounted () {
      this.getCommentList()
    }
  }
  const msg = (msg) => {
    Toast({
      message: msg,
      position: 'bottom',
      duration: 2000
    })
  }
</script>

<style lang="less">
  @c-124: rgb(124, 124, 124);
  @c-169: rgb(169, 169, 169);
  @c-226: rgb(226, 226, 226);
  @c-235: rgb(235, 235, 235);
  @c-red: rgb(255, 129, 98);
  @c-blue: rgb(108, 184, 222);
  @c-dark-blue: rgb(240, 244, 247);

  .act-comment {
    min-height: calc(~'100vh - 58px');
    padding-bottom: 58px;
    overflow-x: hidden;
    overflow-y: scroll;
    background-color: #FFF;
    text-align: left;
    img {
      width: 24px;
      height: 24px;
    }
    header {
      padding: 12px;
      border-bottom: 1px solid @c-235;
      img, span {
        vertical-align: middle;
      }
      span {
        font-size: 13px;
        line-height: 24px;
        color: @c-124;
      }
    }
    footer {
      position: fixed;
      bottom: 0;
      left: 0;
      right: 0;
      top: auto;
      background-color: @c-226;
      box-sizing: border-box;
      padding: 8px 12px;
      border-top: 1px solid @c-226;
      display: flex;
      align-content: center;
      align-items: center;
      justify-content: space-between;
      .mint-field {
        border-radius: 20px;
        min-height: auto;
        height: auto;
        flex: 1;
        display: inline-flex;
        .mint-cell-wrapper {
          padding: 8px 10px;
          .mint-field-core {
            font-size: 12px;
            line-height: 24px;
          }
        }
      }
      .mint-button {
        flex: 0 0 64px;
        border-radius: 20px;
        background-color: @c-blue;
        color: #FFF;
        font-size: 13px;
        line-height: 24px;
        height: auto;
        padding: 8px 19px;
        margin-left: 12px;
      }
    }
    .comment {
      margin: 12px 0 0 12px;
      border-bottom: 1px solid @c-235;
      display: flex;
      justify-content: space-between;
      .head-img {
        flex: 0 0 auto;
        margin-right: 12px;
        img {
          width: 32px;
          height: 32px;
          border-radius: 100%;
        }
      }
      .comment-detail {
        flex: 1;
        text-align: left;
        padding: 0 12px 12px 0;
        .user-name {
          font-size: 13px;
          line-height: 24px;
          font-weight: bold;
          color: @c-124;
          margin-bottom: 12px;
          .floor {
            float: right;
            font-size: 12px;
            font-weight: normal;
            color: @c-169;
          }
          .date-time {
            display: block;
            width: 100%;
            font-size: 12px;
            color: @c-169;
          }
        }
        .detail {
          font-size: 12px;
          line-height: 24px;
          color: @c-124;
          display: -webkit-box;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 2;
          overflow: hidden;
        }
      }
    }
  }  
</style>